<?php 
class BrandController extends AuthController{
	public $db;//模型对象
	public $brand;
	//执行构造函数,创建模型对象
	public function __init(){
		$this->db=K('Brand');
		//读取缓存数据
		$this->brand=S('brand');
	}
	//读取品牌信息列表
	public function index(){
		$this->assign('brand',$this->brand);
		$this->display();
	}
	//添加品牌
	public function add(){
		if(IS_POST){
			// p($_POST);exit;
			if($this->db->addBrand()){
				$this->success('品牌添加成功','index');				
			}else{
				$this->error($this->db->error);
			}
		}else{			
			$this->display();
		}
	}
	//更新品牌
	public function edit(){
		if(IS_POST){
			if($this->db->editBrand()){
				$this->success('品牌编辑成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$bid=Q('brand_id',0,'intval');
			$brand=$this->db->find($bid);
			//缩略图处理，为了编辑时候正常显示
			$brand['brand_logo']=array(
				array('path'=>$brand['brand_logo'])
			);
			$this->assign('brand',$brand);
			$this->display();
		}
	}

	//删除品牌
	public function del(){
		if($this->db->delBrand()){
			$this->success('品牌删除成功','index');
		}else{
			$this->error($this->db->error);
		}
	}

	//更新缓存
	public function upCache(){
		if($this->db->updateCache()){
			$this->success('缓存更新成功','index');
		}else{
			$this->error('缓存更新失败','index');
		}
	}
	//异步删除品牌LOGO
	public function delBrandImg(){
		if($this->db->delBrandLogo()){
			$this->success('删除成功','index');
		}else{
			$this->error($this->db->error);
		}
	}

}

?>